package spark.hope

import java.util.Properties

import org.apache.spark.sql.SQLContext
import org.apache.spark.storage.StorageLevel
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by skybiran on 2015/7/11.
  */
object SparkTest {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("My Spark Test")
//    spark.externalBlockStore.blockManager=org.apache.spark.storage.AlluxioBlockManager
//    spark.externalBlockStore.url=alluxio://localhost:19998
    sparkConf.set("spark.externalBlockStore.blockManager", "org.apache.spark.storage.AlluxioBlockManager")
    sparkConf.set("spark.externalBlockStore.url", "alluxio://localhost:19998")
    val sc = new SparkContext(sparkConf)
    val sqlContext = new SQLContext(sc)

    val url:String = "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC"
    val table:String = "lazy_table"
    val proper = new Properties()
    proper.put("user", "root")
    proper.put("password", "")

    val res = sqlContext.read.jdbc(url, table, proper).persist(StorageLevel.OFF_HEAP)
    res.printSchema()
    res.show()
  }
}
